package cn.edu.lnpu.common.exception;

import cn.edu.lnpu.common.model.response.ResponseResult;
import cn.edu.lnpu.common.model.response.ResultCode;
import lombok.extern.java.Log;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@Log
@ControllerAdvice
public class ExceptionCatch {

    @ExceptionHandler(CustomException.class)
    @ResponseBody
    public ResponseResult customException(CustomException customException){
        ResultCode resultCode = customException.getResultCode();
        log.info(resultCode.message());
        return new ResponseResult(resultCode);
    }
}
